package com.hmall.pay.listener;

import com.hmall.common.constants.MqConstants;
import com.hmall.pay.service.IPayOrderService;
import lombok.RequiredArgsConstructor;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class OrderTOPayListener {
        private  final IPayOrderService payOrderService;

    @RabbitListener(bindings = @QueueBinding(
            value =@Queue(name = MqConstants.PAY_SUCCESS_QUEUE,durable = "true"),
            exchange = @Exchange(value = MqConstants.PAY_DELAY_EXCHANGE,delayed = "true",type = ExchangeTypes.DIRECT),
            key = MqConstants.PAY_SUCCESS_KEY
    ))
    public void payListener(Long orderId){
            payOrderService.tryUpdatePayOrder(orderId);
    }
}
